home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0015_GRPHINIT.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  75 lines

  1. {
  2. The following Unit contains one Function.  This Function will initialize the
  3. Borland BGI Interface in a Turbo Pascal Program.  I wrote this Unit in TP
  4. 5.5, but it should work For all versions of TP after 4.0.
  5.  
  6. The Function performs two actions which I think can help Graphics Programs
  7. immensely.  The first is to obtain the path For the BGI (and CHR) drivers
  8. from an environmental Variable BGIDIR.  The second action is to edit the
  9. driver and mode passed to the initialization Unit against what is detected
  10. by TP.  The Function returns a Boolean to say if it was able to successfully
  11. initialize the driver.
  12.  
  13. I hope this helps someone.
  14. }
  15.  
  16. Unit GrphInit;
  17.  
  18. Interface
  19.  
  20. Uses
  21.         Dos,
  22.         Graph;
  23.  
  24. Function Init_Graphics (Var GraphDriver, GraphMode : Integer) : Boolean;
  25. {        This Function will initialize the Turbo Graphics For the requested
  26.         Graphics mode if and only if the requested mode is valid For the
  27.         machine the Function is run in.  Another feature of this Function is
  28.         that it will look For an environmental Variable named 'BGIDIR'.  If
  29.         this Variable is found, it will attempt to initialize the Graphics
  30.         mode looking For the BGI driver using the String associated With BGIDIR
  31.         as the path.  If the correct BGI driver is not available, or if there is
  32.         not BGIDIR Variable in the environment, it will attempt to initialize
  33.         using the current directory. }
  34.  
  35.  
  36. Implementation
  37.  
  38. Function Init_Graphics (Var GraphDriver, GraphMode : Integer) : Boolean;
  39. Const
  40.         ENV_BGI_PATH = 'BGIDIR';
  41. Var
  42.         BGI_Path        : String;
  43. begin
  44.         { Default to not work }
  45.         Init_Graphics := False;
  46.   BGI_Path := GetEnv(ENV_BGI_PATH);
  47.         InitGraph(GraphDriver,GraphMode,BGI_Path);
  48.         if GraphResult = grOk then
  49.                  Init_Graphics := True
  50.         Else
  51.   begin { Try current Directory }
  52.                 InitGraph(GraphDriver,GraphMode,'');
  53.                 if GraphResult = grOk then
  54.                         Init_Graphics := True;
  55.         end; { Try current Directory }
  56. end; { Function Init_Graphics }
  57.  
  58. end.
  59.  
  60.  
  61. {
  62.  Example File :
  63.  
  64. Uses
  65.   Graph, GrphInit;
  66.  
  67. Const
  68.   Gd     : Integer = 0;
  69.   Gm     : Integer = 0;
  70. begin
  71.   Init_Graphics(Gd, Gm);
  72.   Line(10,10,40,40);
  73.   Readln;
  74. end.
  75. }